package com.stn.zjx.givingtreasure.activity.userlogin;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.came.viewbguilib.ButtonBgUi;
import com.stn.zjx.givingtreasure.R;
import com.stn.zjx.givingtreasure.base.BaseActivity;
import com.stn.zjx.givingtreasure.event.NetWorkEvent;
import com.stn.zjx.givingtreasure.event.UserResetPassEvent;
import com.vondear.rxtools.RxActivityTool;
import com.vondear.rxtools.RxNetTool;
import com.vondear.rxtools.RxRegTool;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class UserPassResetActivity extends BaseActivity {


    @BindView(R.id.back_bt)
    RelativeLayout backBt;
    @BindView(R.id.action_title)
    TextView actionTitle;
    @BindView(R.id.left_star)
    TextView leftStar;
    @BindView(R.id.phone_edit)
    EditText phoneEdit;
    @BindView(R.id.next_bt)
    ButtonBgUi nextBt;

    @Override
    public void networkStatus(NetWorkEvent netWorkEvent) {

    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_userpass_reset);
        ButterKnife.bind(this);
        initComponent();
    }

    @Override
    public void initComponent() {
        actionTitle.setText(getString(R.string.forgetpassword));
    }


    @OnClick({R.id.back_bt, R.id.next_bt})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back_bt:
                finish();
                break;
            case R.id.next_bt:
                if (!sendCheck()) {
                    return;
                }
                Bundle data = new Bundle();
                data.putString("phone", phoneEdit.getText().toString().trim());
                RxActivityTool.skipActivity(this, UserPassResetTwoActivity.class, data);
                break;

        }
    }

    //用户密码登陆检查
    public boolean sendCheck() {
        if (TextUtils.isEmpty(phoneEdit.getText().toString().trim())) {

            showToast(getString(R.string.phone_isnotempty));
            return false;
        }
        if (!RxRegTool.isMobile(phoneEdit.getText().toString().trim())) {

            showToast(getString(R.string.please_isnotreal_phone));
            return false;
        }
        if (!RxNetTool.isAvailable(this)) {

            showToast(getString(R.string.request_networkavailable));
            return false;
        }
        return true;
    }

    @Override
    public boolean isSupportSwipeBack() {
        return true;
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void UserResetPassEvent(UserResetPassEvent event) {
        finish();
    }

}
